﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using BussinessObjects;
using BusinessObjects;
using LibraryO2S;
using BusinessObjects.BO_Actions.Products;
using Entity.StoreProcedure;
using System.Collections.Generic;

public partial class controls_admin_Products : Pages_Base
{
    private string keyword;
    private int cid;
    protected int mid;
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = getRequest("mid", -1);
        cid = getRequest("cid", -1);
        keyword = base.getRequest("k_w", string.Empty);
        base.removeHGC(divMessage);
        base.removeHGC(divResult);
        if (!IsPostBack)
        {
            try
            {
                base.OpenConnection();
                base.loadCategories(ddlCategory, 3);
                if (cid > 0)
                    ddlCategory.SelectedValue = cid.ToString();
                loadData();
            }
            catch (Exception ex)
            {
                divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Có lỗi khi truy cập hệ thống! <br>" + ex.Message);
            }
            finally { base.CloseConnection(); }
        }
    }
    protected void loadData()
    {
        try
        {
            cid = Convert.ToInt32(ddlCategory.SelectedValue);
            objDT = BO_Products.SelectAdmin(keyword, mid, base.Cur_page, base.Page_size, cid);
            bindRepeater(rptData, objDT, pagerContainer, divMessage);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally { base.CloseConnection(); }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        base.search(txtSearch.Value.Trim());
    }
    protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        base.ddlSelectedIndexChanged("cid", ddlCategory);
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        string del_list = hdfCheck.Value;
        string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        BOProducts_Delete _action = new BOProducts_Delete();
        usp_Products_Delete _entity;
        List<usp_Products_Delete> _listData = new List<usp_Products_Delete>();
        foreach (string per in sp_list)
        {
            _entity = new usp_Products_Delete();
            _entity.PRODUCT_ID = Convert.ToInt32(per);
            _listData.Add(_entity);
        }
        if (_action.ExecuteListDataAndReturnBooleanValue(_listData))
            divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Thực hiện thành công.");
        else
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Chưa thực hiện được !");
        loadData();
    }
}
